Skip to content

refactor: make KetchLogger a class with tag constructor parameter#99

Merged
linroid merged 4 commits intomainfrom
claude/refactor-ketchlogger-tag-ZiuJK
Feb 21, 2026
Merged

refactor: make KetchLogger a class with tag constructor parameter#99
linroid merged 4 commits intomainfrom
claude/refactor-ketchlogger-tag-ZiuJK

Conversation

@linroid
Copy link
Owner

@linroid linroid commented Feb 21, 2026

Summary

Refactored the logging system from a static object-based approach to an instance-based approach where each component creates its own KetchLogger instance with a descriptive tag. This improves code clarity and reduces boilerplate by eliminating the need to pass tag strings to every logging call.

Key Changes

  • KetchLogger refactoring: Converted KetchLogger from a static object with tag parameters to a class that takes a tag in its constructor

    • Each logging method (v, d, i, w, e) no longer requires a tag parameter
    • The global Logger backend is now managed via a companion object
    • Tag is automatically prepended to all log messages in the format [tag]
  • Component logger instances: Added private log property to all major components:

    • Ketch - uses tag "Ketch"
    • DownloadCoordinator - uses tag "Coordinator"
    • HttpDownloadSource - uses tag "HttpSource"
    • DownloadScheduler - uses tag "Scheduler"
    • ScheduleManager - uses tag "ScheduleManager"
    • KtorHttpEngine - uses tag "KtorHttpEngine"
    • SourceResolver - uses tag "SourceResolver"
    • SegmentDownloader - uses tag "SegmentDownloader"
    • RangeSupportDetector - uses tag "RangeDetector"
    • TokenBucket - uses tag "TokenBucket"
    • KetchServer - uses tag "KetchServer"
    • NativeMdnsRegistrar - uses tag "NativeMdnsRegistrar"
    • KetchService - uses tag "KetchService"
  • Updated all logging calls: Replaced all KetchLogger.x("Tag") calls with log.x() throughout the codebase

  • Removed TAG constants: Eliminated hardcoded TAG companion object constants from KetchService and KetchServer as they're no longer needed

Implementation Details

The refactoring maintains backward compatibility with the existing Logger interface while improving the developer experience:

  • Components no longer need to remember or pass tag strings
  • Logging calls are more concise and readable
  • The tag is consistently formatted as [ComponentName] in all log messages
  • The global logger backend can still be set once via KetchLogger.setLogger()

https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz

Convert KetchLogger from a singleton object to a normal class that
takes a tag parameter in its constructor. Each component now creates
its own KetchLogger instance, eliminating the redundant tag parameter
from every logging call.

Before: KetchLogger.d("Coordinator") { "message" }
After:  log.d { "message" }  // where log = KetchLogger("Coordinator")

The global Logger backend remains in the companion object, set once
by the Ketch instance and shared across all KetchLogger instances.

https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz
@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

Test Results

1 300 tests  ±0   1 300 ✅ ±0   13s ⏱️ ±0s
   96 suites ±0       0 💤 ±0 
   96 files   ±0       0 ❌ ±0 

Results for commit 39a4954. ± Comparison against base commit 8b44fb0.

♻️ This comment has been updated with latest results.

@linroid linroid changed the title Refactor logging to use instance-based KetchLogger with tags refactor: make KetchLogger a class with tag constructor parameter Feb 21, 2026
All logging methods are now `inline` with a reference-equality check
against Logger.None. When logging is disabled (the default):

- The outer message lambda is eliminated by inlining (no allocation)
- The inner tag-wrapper lambda is skipped by the fast-path check
- Result: true zero-cost logging — no allocations, no virtual calls

When logging is enabled, the only overhead vs before is one cheap
reference comparison per call.

https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz
KetchLogger's inline functions with Logger.None fast-path already handle
lazy evaluation, so Logger implementations don't need lambdas. This
simplifies the Logger interface and eliminates an inner lambda allocation
per log call.

https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz
@linroid linroid merged commit 20d843e into main Feb 21, 2026
4 checks passed
@linroid linroid deleted the claude/refactor-ketchlogger-tag-ZiuJK branch February 21, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants